/*
ID: icerupt1
PROG: combo
LANG: C++11
*/
#include <fstream>
#include <utility>
using namespace std;

int n;

bool tolerance(int x, int y)
{
	if (abs(x-y) < 3) return true;
	if (x > y) swap(x, y);
	if (y == n && x <= 2) return true;
	if (y == n-1 && x == 1) return true;
	return false;
}

bool judge(int x1, int x2, int x3, int y1, int y2, int y3)
{
	if (tolerance(x1, y1) && tolerance(x2, y2) && tolerance(x3, y3))
		return true;
	return false;
}

int main()
{
	ifstream fin {"combo.in" };
	ofstream fout{"combo.out"};

	fin >> n;
	int a1, a2, a3;
	int b1, b2, b3;
	fin >> a1 >> a2 >> a3;
	fin >> b1 >> b2 >> b3;

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				if (judge(i, j, k, a1, a2, a3) || judge(i, j, k, b1, b2, b3))
					ans++;
			}
		}
	}
	fout << ans << "\n";
}

